package JFrame;

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

public class AddListener {
    public static void main(String[] args) {
        myListener  listener=new myListener("监听器测试");

    }
}
class myListener extends JFrame {
    JButton button;
    myListener(String name){
        setTitle(name);
        setBounds(200,200,500,400);
        setLayout(new FlowLayout(FlowLayout.LEFT));
        setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        init();

    }

    private void init() {
        button=new JButton("点击");
        JTextArea area=new JTextArea(10,15);
        area.setLineWrap(true);
        JScrollPane pane=new JScrollPane(area);
        add(area);
        add(pane);
        add(button);
        button.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                area.append("点到我拉！");
            }
        });
    }

}